define(['app'], function(todoApp) {
  todoApp.factory('todoService', function() {
    const storage = 'sessionStorage';
  
    function save({ todoList, archivedList }) {
      window[storage].setItem('todoList', angular.toJson(todoList));
      window[storage].setItem('archivedList', angular.toJson(archivedList));
    }
  
    function query() {
      const todoList = window[storage].getItem('todoList');
      const archivedList = window[storage].getItem('archivedList');
      return {
        todoList: (todoList && angular.fromJson(todoList)) || [],
        archivedList:  (archivedList && angular.fromJson(archivedList)) || []
      };
    }
    
    return {
      save,
      query
    };
  });
});
